<?php
/**
 * Created by PhpStorm.
 * User: priestll
 * Date: 20-7-14
 * Time: 下午4:37
 */

namespace App\HttpController\Common;


use App\Biz\UserBiz;
use EasySwoole\WeChat\Bean\OfficialAccount\JsAuthRequest;
use priestll\easyswoole\http\Base;
use priestll\easyswoole\wechat\WeChatManager;


class Login extends Base
{
    /**
     * @Di(key="USER_BIZ")
     */
    protected $userbiz;

    /**
     * @Api(name="mobile",group="/common/login",description="手机登陆",path="/common/login/mobile")
     * @Method(allow={POST})
     * @ResponseParam(name="code",description="状态码")
     * @ResponseParam(name="result",description="api请求结果")
     * @ResponseParam(name="msg",description="api提示信息")
     * @ApiSuccess({"code":200,"result":[],"msg":"SUCCESS"})
     * @ApiFail({"code":400,"result":[],"msg":"FAIL"})
     * @Param(name="mobile",alias="手机号码",required="",lengthMax="11",'')
     */
    public function mobile()
    {
        return $this->success();
        $param = $this->request()->getRequestParam();
        $res = $this->userbiz->loginByMobile($param['mobile']);
        $userBiz=new UserBiz();
        $res=$userBiz->loginByMobile($param['mobile']);
        if ($res['status']) {
            return $this->success($res['data']);
        } else {
            return $this->fail($res['data']);
        }
    }

    /**
     * @Api(name="code",group="/common/login",description="微信公众号登陆",path="/common/login/offiaccount")
     * @Method(allow={GET})
     * @ResponseParam(name="code",description="状态码")
     * @ResponseParam(name="result",description="api请求结果")
     * @ResponseParam(name="msg",description="api提示信息")
     * @ApiSuccess({"code":200,"result":[],"msg":"SUCCESS"})
     * @ApiFail({"code":400,"result":[],"msg":"FAIL"})
     * @Param(name="code",alias="code",required="")
     */
    public function offiaccount(){
        $param = $this->request()->getRequestParam();
        $userBiz=new UserBiz();
        $res= $userBiz->loginByH5Online($param["code"]);
        if ($res['status']) {
            return $this->success(["token"=>$res['data']["token"],"round"=>$res['data']["round"],"id"=>$res["data"]["id"]]);
        } else {
            return $this->fail($res['data']);
        }
    }
    public function offiaccount2(){
        $param = $this->request()->getRequestParam();
        $userBiz=new UserBiz();
        $res= $userBiz->loginByH5($param["code"]);
        if ($res['status']) {
            return $this->success(["token"=>$res['data']["token"],"round"=>$res['data']["round"],"id"=>$res["data"]["id"]]);
        } else {
            return $this->fail($res['data']);
        }
    }


}